const Koa = require('koa')
const router = require('koa-router')()
const render = require('koa-art-template')
const path = require('path')

//引入子模块
const admin = require('./routes/admin')
const api = require('./routes/api')
const index = require('./routes/index')


const app = new Koa()

//配置koa-art-template模板引擎
render(app, {
  root: path.join(__dirname, 'views'),
  extname: '.html',
  debug: process.env.NODE_ENV !== 'production'
})

//配置路由
router.use(index)

//配置子路由，层级路由
router.use('/admin', admin)
//api路由
router.use('/api', api) //在模块里面暴露路由并启动


//启动路由
app.use(router.routes()).use(router.allowedMethods())
app.listen(8000)